home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 8 / Revista CD Expert nº 08 CD1.iso / Utilitarios / Programacao / Bloodshed Dev-C++ 2.0 / _SETUP.1 / Sockets.h < prev    next >
C/C++ Source or Header  |  1997-06-16  |  31KB  |  958 lines

  1. /* 
  2.    Sockets.h
  3.  
  4.    Windows Sockets specification version 1.1
  5.  
  6.    Copyright (C) 1996 Free Software Foundation, Inc.
  7.    Thanks to Linux header files for supplying many needed definitions
  8.  
  9.    Author:  Scott Christley <scottc@net-community.com>
  10.    Date: 1996
  11.    
  12.    This file is part of the Windows32 API Library.
  13.  
  14.    This library is free software; you can redistribute it and/or
  15.    modify it under the terms of the GNU Library General Public
  16.    License as published by the Free Software Foundation; either
  17.    version 2 of the License, or (at your option) any later version.
  18.    
  19.    This library is distributed in the hope that it will be useful,
  20.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22.    Library General Public License for more details.
  23.  
  24.    If you are interested in a warranty or support for this source code,
  25.    contact Scott Christley <scottc@net-community.com> for more information.
  26.    
  27.    You should have received a copy of the GNU Library General Public
  28.    License along with this library; see the file COPYING.LIB.
  29.    If not, write to the Free Software Foundation, 
  30.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  31. */ 
  32.  
  33. /*-
  34.  * Portions Copyright (c) 1980, 1983, 1988, 1993
  35.  *     The Regents of the University of California.  All rights reserved.
  36.  *
  37.  * Redistribution and use in source and binary forms, with or without
  38.  * modification, are permitted provided that the following conditions
  39.  * are met:
  40.  * 1. Redistributions of source code must retain the above copyright
  41.  *    notice, this list of conditions and the following disclaimer.
  42.  * 2. Redistributions in binary form must reproduce the above copyright
  43.  *    notice, this list of conditions and the following disclaimer in the
  44.  *    documentation and/or other materials provided with the distribution.
  45.  * 3. All advertising materials mentioning features or use of this software
  46.  *    must display the following acknowledgement:
  47.  *    This product includes software developed by the University of
  48.  *    California, Berkeley and its contributors.
  49.  * 4. Neither the name of the University nor the names of its contributors
  50.  *    may be used to endorse or promote products derived from this software
  51.  *    without specific prior written permission.
  52.  *
  53.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  54.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  57.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  58.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  59.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  61.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  63.  * SUCH DAMAGE.
  64.  *
  65.  * -
  66.  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  67.  *
  68.  * Permission to use, copy, modify and distribute this software for any
  69.  * purpose with or without fee is hereby granted, provided that the above
  70.  * copyright notice and this permission notice appear in all copies, and that
  71.  * the name of Digital Equipment Corporation not be used in advertising or
  72.  * publicity pertaining to distribution of the document or software without
  73.  * specific, written prior permission.
  74.  *
  75.  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  76.  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  77.  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  78.  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  79.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  80.  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  81.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  82.  * SOFTWARE.
  83.  * -
  84.  * --Copyright--
  85.  */
  86.  
  87. #ifndef _GNU_H_WINDOWS32_SOCKETS
  88. #define _GNU_H_WINDOWS32_SOCKETS
  89.  
  90. #ifdef __cplusplus
  91. extern "C" {
  92. #endif /* __cplusplus */
  93.  
  94. /* BSD */
  95. typedef unsigned char   u_char;
  96. typedef unsigned short  u_short;
  97. typedef unsigned int    u_int;
  98. typedef unsigned long   u_long;
  99.  
  100. /*
  101.   Default maximium number of sockets.
  102.   Define this before including Sockets.h to increase; this does not
  103.   mean that the underlying Windows Sockets implementation has to
  104.   support that many!
  105.   */
  106. #ifndef FD_SETSIZE
  107. #define FD_SETSIZE      64
  108. #endif /* !FD_SETSIZE */
  109.  
  110. /*
  111.   These macros are critical to the usage of Windows Sockets.
  112.   According to the documentation, a SOCKET is no longer represented
  113.   by a "small non-negative integer"; so all programs MUST use these
  114.   macros for setting, initializing, clearing and checking the
  115.   fd_set structures.
  116.   */
  117.  
  118. typedef u_int           SOCKET;
  119.  
  120. typedef struct fd_set {
  121.         u_int   fd_count;
  122.         SOCKET  fd_array[FD_SETSIZE];
  123. } fd_set;
  124.  
  125. /* Internal function, not documented except in winsock.h */
  126. extern int PASCAL __WSAFDIsSet(SOCKET, fd_set*);
  127.  
  128. #ifdef FD_CLR
  129. #undef FD_CLR
  130. #endif
  131. #define FD_CLR(fd, set) do { \
  132.     u_int __i; \
  133.     for (__i = 0; __i < ((fd_set*)(set))->fd_count ; __i++) { \
  134.         if (((fd_set*)(set))->fd_array[__i] == fd) { \
  135.             while (__i < ((fd_set*)(set))->fd_count-1) { \
  136.                 ((fd_set*)(set))->fd_array[__i] = \
  137.                     ((fd_set*)(set))->fd_array[__i+1]; \
  138.                 __i++; \
  139.             } \
  140.             ((fd_set*)(set))->fd_count--; \
  141.             break; \
  142.         } \
  143.     } \
  144. } while(0)
  145.  
  146. #ifdef FD_SET
  147. #undef FD_SET
  148. #endif
  149. #define FD_SET(fd, set) do { \
  150.     if (((fd_set*)(set))->fd_count < FD_SETSIZE) \
  151.         ((fd_set*)(set))->fd_array[((fd_set*)(set))->fd_count++]=(fd);\
  152. } while(0)
  153.  
  154. #ifdef FD_ZERO
  155. #undef FD_ZERO
  156. #endif
  157. #define FD_ZERO(set) (((fd_set*)(set))->fd_count=0)
  158.  
  159. #ifdef FD_ISSET
  160. #undef FD_ISSET
  161. #endif
  162. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set*)(set))
  163.  
  164. /*
  165.   time structures
  166.   */
  167. struct timeval {
  168.   long tv_sec;     /* seconds */
  169.   long tv_usec;    /* microseconds */
  170. };
  171. struct timezone {
  172.   int tz_minuteswest; /* minutes west of Greenwich */
  173.   int tz_dsttime;     /* type of dst correction */
  174. };
  175.  
  176. /*
  177.  Operations on timevals.
  178.  
  179.  NB: timercmp does not work for >= or <=.
  180.  */
  181. #define    timerisset(tvp)        ((tvp)->tv_sec || (tvp)->tv_usec)
  182. #define    timercmp(tvp, uvp, cmp)    \
  183.     (((tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) \
  184.     || (tvp)->tv_sec cmp (uvp)->tv_sec)
  185. #define    timerclear(tvp)        ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  186.  
  187. /*
  188.   ioctl command encoding.
  189.   Some of this is different than what Linux has
  190.   */
  191. #define IOCPARM_MASK    0x7f
  192. #define IOC_VOID        0x20000000
  193. #define IOC_OUT         0x40000000
  194. #define IOC_IN          0x80000000
  195. #define IOC_INOUT       (IOC_IN | IOC_OUT)
  196.  
  197. /* _IO(magic, subcode) */
  198. #define _IO(c,d)        (IOC_VOID | ((c)<<8) | (d))
  199. /* _IOXX(magic, subcode, arg_t) */
  200. #define _IOW(c,d,t)     (IOC_IN | (((long)sizeof(t) & IOCPARM_MASK)<<16) | \
  201.              ((c)<<8) | (d))
  202. #define _IOR(c,d,t)     (IOC_OUT | (((long)sizeof(t) & IOCPARM_MASK)<<16) | \
  203.              ((c)<<8) | (d))
  204.  
  205. /*
  206.   This stuff is hard-coded on Linux
  207.   But winsock.h uses the macros defined above
  208.   */
  209. #define FIONREAD    _IOR('f', 127, u_long)
  210. #define FIONBIO     _IOW('f', 126, u_long)
  211. #define FIOASYNC    _IOW('f', 125, u_long)
  212.  
  213. #define SIOCSHIWAT  _IOW('s',  0, u_long)
  214. #define SIOCGHIWAT  _IOR('s',  1, u_long)
  215. #define SIOCSLOWAT  _IOW('s',  2, u_long)
  216. #define SIOCGLOWAT  _IOR('s',  3, u_long)
  217. #define SIOCATMARK  _IOR('s',  7, u_long)
  218.  
  219. /*
  220.  Structures returned by network data base library, taken from the
  221.  BSD file netdb.h.  All addresses are supplied in host order, and
  222.  returned in network order (suitable for use in system calls).
  223.  
  224.  Slight modifications for differences between Linux and winsock.h
  225.  */
  226.  
  227. struct  hostent {
  228.   char    *h_name;                /* official name of host */
  229.   char    **h_aliases;            /* alias list */
  230.   short   h_addrtype;             /* host address type */
  231.   short   h_length;               /* length of address */
  232.   char    **h_addr_list;          /* list of addresses */
  233. #define h_addr  h_addr_list[0]    /* address, for backward compat */
  234. };
  235.  
  236. /*
  237.  * Assumption here is that a network number
  238.  * fits in an unsigned long -- someday that won't be true!
  239.  */
  240. struct  netent {
  241.   char    *n_name;      /* official name of net */
  242.   char    **n_aliases;  /* alias list */
  243.   short   n_addrtype;   /* net address type */
  244.   u_long  n_net;        /* network # */
  245. };
  246.  
  247. struct  servent {
  248.   char    *s_name;      /* official service name */
  249.   char    **s_aliases;  /* alias list */
  250.   short   s_port;       /* port # */
  251.   char    *s_proto;     /* protocol to use */
  252. };
  253.  
  254. struct  protoent {
  255.   char    *p_name;      /* official protocol name */
  256.   char    **p_aliases;  /* alias list */
  257.   short   p_proto;      /* protocol # */
  258. };
  259.  
  260. /*
  261.   Standard well-known IP protocols.
  262.   For some reason there are differences between Linx and winsock.h
  263.   */
  264. enum {
  265.   IPPROTO_IP = 0,
  266.   IPPROTO_ICMP = 1,
  267.   IPPROTO_GGP = 2,               /* huh? */
  268.   IPPROTO_IPIP = 4,
  269.   IPPROTO_TCP = 6,               /* Transmission Control Protocol */
  270.   IPPROTO_EGP = 8,
  271.   IPPROTO_PUP = 12,
  272.   IPPROTO_UDP = 17,              /* User Datagram Protocol */
  273.   IPPROTO_IDP = 22,
  274.   IPPROTO_ND = 77,               /* This one was in winsock.h */
  275.  
  276.   IPPROTO_RAW = 255,             /* raw IP packets */
  277.   IPPROTO_MAX
  278. };
  279.  
  280. /* Standard well-known ports */
  281. enum {
  282.   IPPORT_ECHO = 7,
  283.   IPPORT_DISCARD = 9,
  284.   IPPORT_SYSTAT = 11,
  285.   IPPORT_DAYTIME = 13,
  286.   IPPORT_NETSTAT = 15,
  287.   IPPORT_FTP = 21,
  288.   IPPORT_TELNET = 23,
  289.   IPPORT_SMTP = 25,
  290.   IPPORT_TIMESERVER = 37,
  291.   IPPORT_NAMESERVER = 42,
  292.   IPPORT_WHOIS = 43,
  293.   IPPORT_MTP = 57,
  294.  
  295.   IPPORT_TFTP = 69,
  296.   IPPORT_RJE = 77,
  297.   IPPORT_FINGER = 79,
  298.   IPPORT_TTYLINK = 87,
  299.   IPPORT_SUPDUP = 95,
  300.  
  301.   IPPORT_EXECSERVER = 512,
  302.   IPPORT_LOGINSERVER = 513,
  303.   IPPORT_CMDSERVER = 514,
  304.   IPPORT_EFSSERVER = 520,
  305.  
  306.   /* UDP ports. */
  307.   IPPORT_BIFFUDP = 512,
  308.   IPPORT_WHOSERVER = 513,
  309.   IPPORT_ROUTESERVER = 520,
  310.  
  311.   /* Ports less than this value are reservered for privileged processes. */
  312.   IPPORT_RESERVED = 1024,
  313.  
  314.   /* Ports greater than this value are reserved for 
  315.      (non-privileged) processes */
  316.   IPPORT_USERRESERVED = 5000
  317. };
  318.  
  319. /* Link numbers. */
  320. #define IMPLINK_IP              155
  321. #define IMPLINK_LOWEXPER        156
  322. #define IMPLINK_HIGHEXPER       158
  323.  
  324. /* Linux uses a simple unsigned long int, but winsock.h ... */
  325. struct in_addr {
  326.         union {
  327.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  328.                 struct { u_short s_w1,s_w2; } S_un_w;
  329.                 u_long S_addr;
  330.         } S_un;
  331. #define s_addr  S_un.S_addr
  332. #define s_host  S_un.S_un_b.s_b2
  333. #define s_net   S_un.S_un_b.s_b1
  334. #define s_imp   S_un.S_un_w.s_w2
  335. #define s_impno S_un.S_un_b.s_b4
  336. #define s_lh    S_un.S_un_b.s_b3
  337. };
  338.  
  339. /*
  340.  Definitions of bits in internet address integers.
  341.  On subnets, host and network parts are found according
  342.  to the subnet mask, not these masks.
  343.  */
  344. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  345. #define IN_CLASSA_NET           0xff000000
  346. #define IN_CLASSA_NSHIFT        24
  347. #define IN_CLASSA_HOST          0x00ffffff
  348. #define IN_CLASSA_MAX           128
  349.  
  350. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  351. #define IN_CLASSB_NET           0xffff0000
  352. #define IN_CLASSB_NSHIFT        16
  353. #define IN_CLASSB_HOST          0x0000ffff
  354. #define IN_CLASSB_MAX           65536
  355.  
  356. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  357. #define IN_CLASSC_NET           0xffffff00
  358. #define IN_CLASSC_NSHIFT        8
  359. #define IN_CLASSC_HOST          0x000000ff
  360.  
  361. #define INADDR_ANY              (u_long)0x00000000
  362. #define INADDR_LOOPBACK         0x7f000001
  363. #define INADDR_BROADCAST        (u_long)0xffffffff    
  364. #define INADDR_NONE             0xffffffff
  365.  
  366. /*
  367.  Structure describing an Internet (IP) socket address.
  368.  */
  369. struct sockaddr_in {
  370.   short   sin_family;
  371.   u_short sin_port;
  372.   struct  in_addr sin_addr;
  373.   char    sin_zero[8];
  374. };
  375.  
  376. /*
  377.   EVERYTHING FROM THIS POINT IS MAINLY SPECIFIC TO Win32
  378.  
  379.   Structure which holds the detail for the underlying Window Sockets
  380.   implementation.  Set when WSAStartup() is called.
  381.   */
  382. #define WSADESCRIPTION_LEN      256
  383. #define WSASYS_STATUS_LEN       128
  384.  
  385. typedef struct WSAData {
  386.   WORD wVersion;
  387.   WORD wHighVersion;
  388.   char szDescription[WSADESCRIPTION_LEN+1];
  389.   char szSystemStatus[WSASYS_STATUS_LEN+1];
  390.   unsigned short iMaxSockets;
  391.   unsigned short iMaxUdpDg;
  392.   char *lpVendorInfo;
  393. } WSADATA, *LPWSADATA;
  394.  
  395. #define IP_OPTIONS          1
  396. #define IP_MULTICAST_IF     2
  397. #define IP_MULTICAST_TTL    3
  398. #define IP_MULTICAST_LOOP   4
  399. #define IP_ADD_MEMBERSHIP   5
  400. #define IP_DROP_MEMBERSHIP  6
  401.  
  402. #define IP_DEFAULT_MULTICAST_TTL   1
  403. #define IP_DEFAULT_MULTICAST_LOOP  1
  404. #define IP_MAX_MEMBERSHIPS         20
  405.  
  406. struct ip_mreq {
  407.   struct in_addr imr_multiaddr;
  408.   struct in_addr imr_interface;
  409. };
  410.  
  411. /*
  412.  * Definitions related to sockets: types, address families, options,
  413.  * taken from the BSD file sys/socket.h.
  414.  */
  415.  
  416. /*
  417.  * This is used instead of -1, since the
  418.  * SOCKET type is unsigned.
  419.  */
  420. #define INVALID_SOCKET  (SOCKET)(~0)
  421. #define SOCKET_ERROR            (-1)
  422.  
  423. /* Socket types. */
  424. #define SOCK_STREAM     1
  425. #define SOCK_DGRAM      2
  426. #define SOCK_RAW        3
  427. #define SOCK_RDM        4 
  428. #define SOCK_SEQPACKET  5
  429.  
  430. /* For setsockoptions(2) */
  431. #define SO_DEBUG        0x0001
  432. #define SO_ACCEPTCONN   0x0002
  433. #define SO_REUSEADDR    0x0004
  434. #define SO_KEEPALIVE    0x0008
  435. #define SO_DONTROUTE    0x0010
  436. #define SO_BROADCAST    0x0020
  437. #define SO_USELOOPBACK  0x0040
  438. #define SO_LINGER       0x0080
  439. #define SO_OOBINLINE    0x0100
  440.  
  441. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  442.  
  443. /*
  444.  * Additional options.
  445.  */
  446. #define SO_SNDBUF       0x1001          /* send buffer size */
  447. #define SO_RCVBUF       0x1002          /* receive buffer size */
  448. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  449. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  450. #define SO_SNDTIMEO     0x1005          /* send timeout */
  451. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  452. #define SO_ERROR        0x1007          /* get error status and clear */
  453. #define SO_TYPE         0x1008          /* get socket type */
  454.  
  455. /*
  456.  * Options for connect and disconnect data and options.  Used only by
  457.  * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  458.  */
  459. #define SO_CONNDATA     0x7000
  460. #define SO_CONNOPT      0x7001
  461. #define SO_DISCDATA     0x7002
  462. #define SO_DISCOPT      0x7003
  463. #define SO_CONNDATALEN  0x7004
  464. #define SO_CONNOPTLEN   0x7005
  465. #define SO_DISCDATALEN  0x7006
  466. #define SO_DISCOPTLEN   0x7007
  467.  
  468. /*
  469.  * Option for opening sockets for synchronous access.
  470.  */
  471. #define SO_OPENTYPE     0x7008
  472.  
  473. #define SO_SYNCHRONOUS_ALERT    0x10
  474. #define SO_SYNCHRONOUS_NONALERT 0x20
  475.  
  476. /*
  477.  * Other NT-specific options.
  478.  */
  479. #define SO_MAXDG        0x7009
  480. #define SO_MAXPATHDG    0x700A
  481.  
  482. /*
  483.  * TCP options.
  484.  */
  485. #define TCP_NODELAY     0x0001
  486. #define TCP_BSDURGENT   0x7000
  487.  
  488. /*
  489.  * Address families.
  490.  */
  491. #define AF_UNSPEC       0               /* unspecified */
  492. #define AF_UNIX         1               /* local to host (pipes, portals) */
  493. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  494. #define AF_IMPLINK      3               /* arpanet imp addresses */
  495. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  496. #define AF_CHAOS        5               /* mit CHAOS protocols */
  497. #define AF_IPX          6               /* IPX and SPX */
  498. #define AF_NS           6               /* XEROX NS protocols */
  499. #define AF_ISO          7               /* ISO protocols */
  500. #define AF_OSI          AF_ISO          /* OSI is ISO */
  501. #define AF_ECMA         8               /* european computer manufacturers */
  502. #define AF_DATAKIT      9               /* datakit protocols */
  503. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  504. #define AF_SNA          11              /* IBM SNA */
  505. #define AF_DECnet       12              /* DECnet */
  506. #define AF_DLI          13              /* Direct data link interface */
  507. #define AF_LAT          14              /* LAT */
  508. #define AF_HYLINK       15              /* NSC Hyperchannel */
  509. #define AF_APPLETALK    16              /* AppleTalk */
  510. #define AF_NETBIOS      17              /* NetBios-style addresses */
  511.  
  512. #define AF_MAX          18
  513.  
  514. /*
  515.  * Structure used by kernel to store most
  516.  * addresses.
  517.  */
  518. struct sockaddr {
  519.   u_short sa_family;
  520.   char    sa_data[14];
  521. };
  522.  
  523. /*
  524.  * Structure used by kernel to pass protocol
  525.  * information in raw sockets.
  526.  */
  527. struct sockproto {
  528.   u_short sp_family;
  529.   u_short sp_protocol;
  530. };
  531.  
  532. /*
  533.  * Protocol families, same as address families for now.
  534.  */
  535. #define PF_UNSPEC       AF_UNSPEC
  536. #define PF_UNIX         AF_UNIX
  537. #define PF_INET         AF_INET
  538. #define PF_IMPLINK      AF_IMPLINK
  539. #define PF_PUP          AF_PUP
  540. #define PF_CHAOS        AF_CHAOS
  541. #define PF_NS           AF_NS
  542. #define PF_IPX          AF_IPX
  543. #define PF_ISO          AF_ISO
  544. #define PF_OSI          AF_OSI
  545. #define PF_ECMA         AF_ECMA
  546. #define PF_DATAKIT      AF_DATAKIT
  547. #define PF_CCITT        AF_CCITT
  548. #define PF_SNA          AF_SNA
  549. #define PF_DECnet       AF_DECnet
  550. #define PF_DLI          AF_DLI
  551. #define PF_LAT          AF_LAT
  552. #define PF_HYLINK       AF_HYLINK
  553. #define PF_APPLETALK    AF_APPLETALK
  554.  
  555. #define PF_MAX          AF_MAX
  556.  
  557. /*
  558.  * Structure used for manipulating linger option.
  559.  */
  560. struct  linger {
  561.   u_short l_onoff;
  562.   u_short l_linger;
  563. };
  564.  
  565. /*
  566.  * Level number for (get/set)sockopt() to apply to socket itself.
  567.  */
  568. #define SOL_SOCKET      0xffff          /* options for socket level */
  569.  
  570. /*
  571.  * Maximum queue length specifiable by listen.
  572.  */
  573. #define SOMAXCONN       5
  574.  
  575. #define MSG_OOB         0x1             /* process out-of-band data */
  576. #define MSG_PEEK        0x2             /* peek at incoming message */
  577. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  578.  
  579. #define MSG_MAXIOVLEN   16
  580.  
  581. #define    MSG_PARTIAL     0x8000          /* partial send or recv for message xport */
  582.  
  583. /*
  584.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  585.  */
  586. #define MAXGETHOSTSTRUCT        1024
  587. #define MAXHOSTNAMELEN          MAXGETHOSTSTRUCT
  588.  
  589. /*
  590.  * Define flags to be used with the WSAAsyncSelect() call.
  591.  */
  592. #define FD_READ         0x01
  593. #define FD_WRITE        0x02
  594. #define FD_OOB          0x04
  595. #define FD_ACCEPT       0x08
  596. #define FD_CONNECT      0x10
  597. #define FD_CLOSE        0x20
  598.  
  599. /*
  600.  * All Windows Sockets error constants are biased by WSABASEERR from
  601.  * the "normal"
  602.  */
  603. #define WSABASEERR              10000
  604. /*
  605.  * Windows Sockets definitions of regular Microsoft C error constants
  606.  */
  607. #define WSAEINTR                (WSABASEERR+4)
  608. #define WSAEBADF                (WSABASEERR+9)
  609. #define WSAEACCES               (WSABASEERR+13)
  610. #define WSAEFAULT               (WSABASEERR+14)
  611. #define WSAEINVAL               (WSABASEERR+22)
  612. #define WSAEMFILE               (WSABASEERR+24)
  613.  
  614. /*
  615.  * Windows Sockets definitions of regular Berkeley error constants
  616.  */
  617. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  618. #define WSAEINPROGRESS          (WSABASEERR+36)
  619. #define WSAEALREADY             (WSABASEERR+37)
  620. #define WSAENOTSOCK             (WSABASEERR+38)
  621. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  622. #define WSAEMSGSIZE             (WSABASEERR+40)
  623. #define WSAEPROTOTYPE           (WSABASEERR+41)
  624. #define WSAENOPROTOOPT          (WSABASEERR+42)
  625. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  626. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  627. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  628. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  629. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  630. #define WSAEADDRINUSE           (WSABASEERR+48)
  631. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  632. #define WSAENETDOWN             (WSABASEERR+50)
  633. #define WSAENETUNREACH          (WSABASEERR+51)
  634. #define WSAENETRESET            (WSABASEERR+52)
  635. #define WSAECONNABORTED         (WSABASEERR+53)
  636. #define WSAECONNRESET           (WSABASEERR+54)
  637. #define WSAENOBUFS              (WSABASEERR+55)
  638. #define WSAEISCONN              (WSABASEERR+56)
  639. #define WSAENOTCONN             (WSABASEERR+57)
  640. #define WSAESHUTDOWN            (WSABASEERR+58)
  641. #define WSAETOOMANYREFS         (WSABASEERR+59)
  642. #define WSAETIMEDOUT            (WSABASEERR+60)
  643. #define WSAECONNREFUSED         (WSABASEERR+61)
  644. #define WSAELOOP                (WSABASEERR+62)
  645. #define WSAENAMETOOLONG         (WSABASEERR+63)
  646. #define WSAEHOSTDOWN            (WSABASEERR+64)
  647. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  648. #define WSAENOTEMPTY            (WSABASEERR+66)
  649. #define WSAEPROCLIM             (WSABASEERR+67)
  650. #define WSAEUSERS               (WSABASEERR+68)
  651. #define WSAEDQUOT               (WSABASEERR+69)
  652. #define WSAESTALE               (WSABASEERR+70)
  653. #define WSAEREMOTE              (WSABASEERR+71)
  654.  
  655. #define WSAEDISCON              (WSABASEERR+101)
  656.  
  657. /*
  658.  * Extended Windows Sockets error constant definitions
  659.  */
  660. #define WSASYSNOTREADY          (WSABASEERR+91)
  661. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  662. #define WSANOTINITIALISED       (WSABASEERR+93)
  663.  
  664. /*
  665.  * Error return codes from gethostbyname() and gethostbyaddr()
  666.  * (when using the resolver). Note that these errors are
  667.  * retrieved via WSAGetLastError() and must therefore follow
  668.  * the rules for avoiding clashes with error numbers from
  669.  * specific implementations or language run-time systems.
  670.  * For this reason the codes are based at WSABASEERR+1001.
  671.  * Note also that [WSA]NO_ADDRESS is defined only for
  672.  * compatibility purposes.
  673.  */
  674.  
  675. #define h_errno         WSAGetLastError()
  676.  
  677. /* Authoritative Answer: Host not found */
  678. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  679. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  680.  
  681. /* Non-Authoritative: Host not found, or SERVERFAIL */
  682. #define WSATRY_AGAIN            (WSABASEERR+1002)
  683. #define TRY_AGAIN               WSATRY_AGAIN
  684.  
  685. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  686. #define WSANO_RECOVERY          (WSABASEERR+1003)
  687. #define NO_RECOVERY             WSANO_RECOVERY
  688.  
  689. /* Valid name, no data record of requested type */
  690. #define WSANO_DATA              (WSABASEERR+1004)
  691. #define NO_DATA                 WSANO_DATA
  692.  
  693. /* no address, look for MX record */
  694. #define WSANO_ADDRESS           WSANO_DATA
  695. #define NO_ADDRESS              WSANO_ADDRESS
  696.  
  697. /*
  698.  * Windows Sockets errors redefined as regular Berkeley error constants.
  699.  * These are commented out in Windows NT to avoid conflicts with errno.h.
  700.  * Use the WSA constants instead.
  701.  */
  702. #if 0
  703. #define EWOULDBLOCK             WSAEWOULDBLOCK
  704. #define EINPROGRESS             WSAEINPROGRESS
  705. #define EALREADY                WSAEALREADY
  706. #define ENOTSOCK                WSAENOTSOCK
  707. #define EDESTADDRREQ            WSAEDESTADDRREQ
  708. #define EMSGSIZE                WSAEMSGSIZE
  709. #define EPROTOTYPE              WSAEPROTOTYPE
  710. #define ENOPROTOOPT             WSAENOPROTOOPT
  711. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  712. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  713. #define EOPNOTSUPP              WSAEOPNOTSUPP
  714. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  715. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  716. #define EADDRINUSE              WSAEADDRINUSE
  717. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  718. #define ENETDOWN                WSAENETDOWN
  719. #define ENETUNREACH             WSAENETUNREACH
  720. #define ENETRESET               WSAENETRESET
  721. #define ECONNABORTED            WSAECONNABORTED
  722. #define ECONNRESET              WSAECONNRESET
  723. #define ENOBUFS                 WSAENOBUFS
  724. #define EISCONN                 WSAEISCONN
  725. #define ENOTCONN                WSAENOTCONN
  726. #define ESHUTDOWN               WSAESHUTDOWN
  727. #define ETOOMANYREFS            WSAETOOMANYREFS
  728. #define ETIMEDOUT               WSAETIMEDOUT
  729. #define ECONNREFUSED            WSAECONNREFUSED
  730. #define ELOOP                   WSAELOOP
  731. #define ENAMETOOLONG            WSAENAMETOOLONG
  732. #define EHOSTDOWN               WSAEHOSTDOWN
  733. #define EHOSTUNREACH            WSAEHOSTUNREACH
  734. #define ENOTEMPTY               WSAENOTEMPTY
  735. #define EPROCLIM                WSAEPROCLIM
  736. #define EUSERS                  WSAEUSERS
  737. #define EDQUOT                  WSAEDQUOT
  738. #define ESTALE                  WSAESTALE
  739. #define EREMOTE                 WSAEREMOTE
  740. #endif
  741.  
  742. /* Socket function prototypes */
  743.  
  744. SOCKET PASCAL accept (SOCKET s, struct sockaddr *addr,
  745.                           int *addrlen);
  746.  
  747. int PASCAL bind (SOCKET s, const struct sockaddr *addr, int namelen);
  748.  
  749. int PASCAL closesocket (SOCKET s);
  750.  
  751. int PASCAL connect (SOCKET s, const struct sockaddr *name, int namelen);
  752.  
  753. int PASCAL ioctlsocket (SOCKET s, long cmd, u_long *argp);
  754.  
  755. int PASCAL getpeername (SOCKET s, struct sockaddr *name,
  756.                             int * namelen);
  757.  
  758. int PASCAL getsockname (SOCKET s, struct sockaddr *name,
  759.                             int * namelen);
  760.  
  761. int PASCAL getsockopt (SOCKET s, int level, int optname,
  762.                            char * optval, int *optlen);
  763.  
  764. u_long PASCAL htonl (u_long hostlong);
  765.  
  766. /* For some reason WSOCK.LIB has htons defined as a 4 byte paramter?! */
  767. #ifdef _WIN32
  768. u_short PASCAL htons (u_long hostshort);
  769. #else
  770. u_short PASCAL htons (u_short hostshort);
  771. #endif /* _WIN32 */
  772.  
  773. unsigned long PASCAL inet_addr (const char * cp);
  774.  
  775. char * PASCAL inet_ntoa (struct in_addr in);
  776.  
  777. int PASCAL listen (SOCKET s, int backlog);
  778.  
  779. u_long PASCAL ntohl (u_long netlong);
  780.  
  781. /* For some reason WSOCK.LIB has ntohs defined as a 4 byte paramter?! */
  782. #ifdef _WIN32
  783. u_short PASCAL ntohs (u_long netshort);
  784. #else
  785. u_short PASCAL ntohs (u_short netshort);
  786. #endif /* _WIN32 */
  787.  
  788. int PASCAL recv (SOCKET s, char * buf, int len, int flags);
  789.  
  790. int PASCAL recvfrom (SOCKET s, char * buf, int len, int flags,
  791.                          struct sockaddr *from, int * fromlen);
  792.  
  793. int PASCAL select (int nfds, fd_set *readfds, fd_set *writefds,
  794.                        fd_set *exceptfds, const struct timeval *timeout);
  795.  
  796. int PASCAL send (SOCKET s, const char * buf, int len, int flags);
  797.  
  798. int PASCAL sendto (SOCKET s, const char * buf, int len, int flags,
  799.                        const struct sockaddr *to, int tolen);
  800.  
  801. int PASCAL setsockopt (SOCKET s, int level, int optname,
  802.                            const char * optval, int optlen);
  803.  
  804. int PASCAL shutdown (SOCKET s, int how);
  805.  
  806. SOCKET PASCAL socket (int af, int type, int protocol);
  807.  
  808. /* Database function prototypes */
  809.  
  810. struct hostent * PASCAL gethostbyaddr(const char * addr,
  811.                                               int len, int type);
  812.  
  813. struct hostent * PASCAL gethostbyname(const char * name);
  814.  
  815. int PASCAL gethostname (char * name, int namelen);
  816.  
  817. struct servent * PASCAL getservbyport(int port, const char * proto);
  818.  
  819. struct servent * PASCAL getservbyname(const char * name,
  820.                                               const char * proto);
  821.  
  822. struct protoent * PASCAL getprotobynumber(int proto);
  823.  
  824. struct protoent * PASCAL getprotobyname(const char * name);
  825.  
  826. /* Microsoft Windows Extension function prototypes */
  827.  
  828. /* int PASCAL WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData); */
  829. int PASCAL WSAStartup(int wVersionRequired, LPWSADATA lpWSAData);
  830.  
  831.  
  832. int PASCAL WSACleanup(void);
  833.  
  834. void PASCAL WSASetLastError(int iError);
  835.  
  836. int PASCAL WSAGetLastError(void);
  837.  
  838. WINBOOL PASCAL WSAIsBlocking(void);
  839.  
  840. int PASCAL WSAUnhookBlockingHook(void);
  841.  
  842. FARPROC PASCAL WSASetBlockingHook(FARPROC lpBlockFunc);
  843.  
  844. int PASCAL WSACancelBlockingCall(void);
  845.  
  846. HANDLE PASCAL WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  847.                                         const char * name, 
  848.                                         const char * proto,
  849.                                         char * buf, int buflen);
  850.  
  851. HANDLE PASCAL WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  852.                                         const char * proto, char * buf,
  853.                                         int buflen);
  854.  
  855. HANDLE PASCAL WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  856.                                          const char * name, char * buf,
  857.                                          int buflen);
  858.  
  859. HANDLE PASCAL WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  860.                                            int number, char * buf,
  861.                                            int buflen);
  862.  
  863. HANDLE PASCAL WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  864.                                         const char * name, char * buf,
  865.                                         int buflen);
  866.  
  867. HANDLE PASCAL WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  868.                                         const char * addr, int len, int type,
  869.                                         char * buf, int buflen);
  870.  
  871. int PASCAL WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  872.  
  873. int PASCAL WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  874.                                long lEvent);
  875.  
  876. int PASCAL WSARecvEx (SOCKET s, char * buf, int len, int *flags);
  877.  
  878. /* Microsoft Windows Extended data types */
  879. typedef struct sockaddr SOCKADDR;
  880. typedef struct sockaddr *PSOCKADDR;
  881. typedef struct sockaddr *LPSOCKADDR;
  882.  
  883. typedef struct sockaddr_in SOCKADDR_IN;
  884. typedef struct sockaddr_in *PSOCKADDR_IN;
  885. typedef struct sockaddr_in *LPSOCKADDR_IN;
  886.  
  887. typedef struct linger LINGER;
  888. typedef struct linger *PLINGER;
  889. typedef struct linger *LPLINGER;
  890.  
  891. typedef struct in_addr IN_ADDR;
  892. typedef struct in_addr *PIN_ADDR;
  893. typedef struct in_addr *LPIN_ADDR;
  894.  
  895. typedef struct fd_set FD_SET;
  896. typedef struct fd_set *PFD_SET;
  897. typedef struct fd_set *LPFD_SET;
  898.  
  899. typedef struct hostent HOSTENT;
  900. typedef struct hostent *PHOSTENT;
  901. typedef struct hostent *LPHOSTENT;
  902.  
  903. typedef struct servent SERVENT;
  904. typedef struct servent *PSERVENT;
  905. typedef struct servent *LPSERVENT;
  906.  
  907. typedef struct protoent PROTOENT;
  908. typedef struct protoent *PPROTOENT;
  909. typedef struct protoent *LPPROTOENT;
  910.  
  911. typedef struct timeval TIMEVAL;
  912. typedef struct timeval *PTIMEVAL;
  913. typedef struct timeval *LPTIMEVAL;
  914.  
  915. /*
  916.  * Windows message parameter composition and decomposition
  917.  * macros.
  918.  *
  919.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  920.  * when constructing the response to a WSAAsyncGetXByY() routine.
  921.  */
  922. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  923. /*
  924.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  925.  * when constructing the response to WSAAsyncSelect().
  926.  */
  927. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  928. /*
  929.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  930.  * to extract the buffer length from the lParam in the response
  931.  * to a WSAGetXByY().
  932.  */
  933. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  934. /*
  935.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  936.  * to extract the error code from the lParam in the response
  937.  * to a WSAGetXByY().
  938.  */
  939. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  940. /*
  941.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  942.  * to extract the event code from the lParam in the response
  943.  * to a WSAAsyncSelect().
  944.  */
  945. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  946. /*
  947.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  948.  * to extract the error code from the lParam in the response
  949.  * to a WSAAsyncSelect().
  950.  */
  951. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  952.  
  953. #ifdef __cplusplus
  954. }
  955. #endif /* __cplusplus */
  956.  
  957. #endif /* _GNU_H_WINDOWS32_SOCKETS */
  958.